class Solution {
public:
    int minimumRefill(vector<int>& A, int a, int b)
    {
        //0 1 1  1 1  1 0
        int a1 = a;
        int b1 = b;
        int n = A.size();
        int ans = 0;
        int i = 0;
        int j = n - 1;
        while (i <= j)
        {
            if (i == j)
            {
                if (a < A[i] && b < A[i])
                    ans++;
                break;

            }

            if (a < A[i]) a = a1, ans++;
            a -= A[i++];
            if (b < A[j]) b = b1, ans++;
            b -= A[j--];
        }
        return ans;
    }
};